/**
 * @file
 */
#ifndef HASH_H_
#define HASH_H_

#include <stdlib.h>
#include <string.h>

/**
 * Node data structure, used to create the hash table.
 */
typedef struct node {
  char *data; /**< The key. */
  struct node *next; /**< The next node, in case two keys correspond to the same hash. */

  struct circuit_item *net_item; /**< The circuit item itself.*/
} node;

/**
 * Allocate memory for a hash table of size 'size' and return a pointer to it
 * a null pointer is returned in case of failure
 * @param size Size of the hash table to be created
 * @return A pointer to the created hash table, or NULL if allocation was not possible.
 */
node** create_hash_table(int size);


/**
 * Create a hash value for the given key.
 * @param key: Input key.
 * @param len: Length of key.
 * @return Hash of the key.
 */
unsigned djb_hash (char *key, int len);

/**
 * Return a pointer to an existing circuit item with the specified key.
 * @param table Table where to look in.
 * @param size Size of the hash table.
 * @param key Key of the item that is requested.
 * @return A Pointer to a circuit_item.
 */
struct circuit_item * get_circuit_item (node *table[], int size, char *key);


/**
 * Look for an existing entry in the hash table,
 * return 1 if successful hit, otherwise return 0
 * @param table Table where to look in.
 * @param size Size of that table.
 * @param key Key of the desired item.
 * @return 0 if the item is not found, 1 if it is.
 */
int find(node *table[], int size, char *key);


/**
 * Add a circuit_item to the hash table
 * return
 * @param table Table where to insert items.
 * @param size Size of that table.
 * @param key Key of the circuit item.
 * @param net The circuit_item that is going to be inserted.
 * @return 1 if the item is inserted, otherwise 0
 */
int insert(node *table[], int size, char *key, struct circuit_item *net);

/*   */
/**
 * Clean all the entries of the hash table
 * @param table Table to be cleaned.
 * @param size Size of the table.
 */
void clean_hash(node *table[], int size);


#endif /*HASH_H_*/

